<br />
<div id="total" style="font-style: italic; color: red;"></div>
<br />
<br />
<hr />
<br />
<?php
    if( isset($_REQUEST['key2']))
    {
        $tenSP = $_REQUEST["key2"];
        $from = $_REQUEST["from"];
        $to = $_REQUEST["to"];
        $hsx = $_REQUEST["hsx"];
        $loaisp = $_REQUEST["loaisp"];
        $t = 1;
        if($hsx != 0 && $loaisp != 0)
        {
        $query = "
        SELECT * FROM sanpham s, nguoidung nd 
        WHERE nd.MaND = s.MaND 
        AND s.TenSP LIKE '%".$tenSP."%' 
        AND s.MaLSP = '".$loaisp."'
        AND s.MaHSX = '".$hsx."'
        AND s.GiaSP BETWEEN ".$from." AND ".$to."
        ";
        $result = DataProvider::ExecuteQuery($query);
        while($row = mysql_fetch_array($result))
	   {
	        include("templateSanPham.php"); 
            $t++;
	   }
       }
       else
       {
            if($loaisp != 0)
            {
            $query = "
            SELECT * FROM sanpham s, nguoidung nd 
            WHERE nd.MaND = s.MaND 
            AND s.TenSP LIKE '%".$tenSP."%' 
            AND s.MaLSP = '".$loaisp."'
            AND s.GiaSP BETWEEN ".$from." AND ".$to."
            ";
            $result = DataProvider::ExecuteQuery($query);
            while($row = mysql_fetch_array($result))
    	   {
    	        include("templateSanPham.php"); 
                $t++;
    	   }
           }
           else
           {
            $query = "
            SELECT * FROM sanpham s, nguoidung nd 
            WHERE nd.MaND = s.MaND 
            AND s.TenSP LIKE '%".$tenSP."%' 
            AND s.GiaSP BETWEEN ".$from." AND ".$to."
            ";
            $result = DataProvider::ExecuteQuery($query);
            while($row = mysql_fetch_array($result))
    	   {
    	        include("templateSanPham.php"); 
                $t++;
    	   }
           }
       }
       ?>
        <!-- input tạm lấy dữ liệu tổng số sp -->
        <div id="temp">
        <input  type="text" value="Có Tổng Cộng -- <?php echo $t - 1 ; ?> -- Sản Phẩm Thỏa Yêu Cầu" id="total_"/>
        </div>
        
        <?php  
    }
    else
        header("location:trangchu.php");
?>



<script type="text/javascript" >
        //chép dữ liệu vào div có id là total
        var vaNode = document.getElementById("total_");
		var vitriNode = document.getElementById("total");
		var divNode = document.createElement("div");
		vitriNode.appendChild(divNode);
		var textNode = document.createTextNode(vaNode.value);
		divNode.appendChild(textNode);
        
        //remove temp
        var element = document.getElementById("temp");
        if ( element.hasChildNodes() )
        {
            while ( element.childNodes.length >= 0 )
            {
            element.removeChild( element.firstChild );       
            }
        }
        

</script>